package com.DosonLeung.homeschoolcommunication.Constant;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by DosonLeung on 2014/10/21.
 */
public class SystemConstant {
    //Activity code码
    public static final int GET_PHOTO_FROM_ALBUM = 1001;
    public static final int GET_PHOTO_FROM_CAMERA = 1002;
    public static final int CHAT_CODE = 1003;
    public static final int LOG_STRANGE = 4444;
    //相册图片缩放系数
    public final static int SCALE = 10;
    //获取囚牛图片的地址前段
    public static final String DOWN_LOAD_IMAGE_PRE = "http://jiaxiaotong.qiniudn.com/%s";
    //上传图片成功的msg代码
    public static final int UPLOAD_IMAGE_SUCCESS = 0x206;
    //上传声音成功的msg代码
    public static final int UPLOAD_AUDIO_SUCCESS = 0x207;
    //上传图片失败的msg代码
    public static final int UPLOAD_IMAGE_FAIL = 0x406;
    //上传声音失败的msg代码
    public static final int UPLOAD_AUDIO_FAIL = 0x407;
    //下载音频成功的msg代码
    public static final int DOWNLOAD_AUDIO_SUCCESS = 0X208;
    //系统是否在播放
    public static boolean voiceIsPlaying = false;
    //系统是否在录音
    public static boolean voiceIsRecording = false;
    //收到新消息提醒
    public static boolean autonotify = false;
    //消息计数队列
    private static ArrayList<HashMap<String,String>> newsRegister = new ArrayList<HashMap<String, String>>();
    //清空某uid的计数同步方法
    public synchronized static void clearNewInRegister(String uid){
        HashMap<String,String> item;
        int size = newsRegister.size();
        int i;
        for(i = 0;i < size;i++){
            item = newsRegister.get(i);
            if(item.get("uid").equals(uid)) {
                item.remove("Sum");
                item.put("Sum","0");
                break;
            }
        }
    }
    //添加某uid的计数值的同步方法
    public synchronized static void addNewInRegister(String uid){
        HashMap<String,String> item;
        int size = newsRegister.size();
        String Sum;
        int i;
        for(i = 0;i < size;i++){
            item = newsRegister.get(i);
            if(item.get("uid").equals(uid)) {
                Sum = item.get("Sum");
                Sum = String.valueOf((Integer.parseInt(Sum)) + 1);
                item.remove("Sum");
                item.put("Sum", Sum);
                break;
            }
        }
        if(i==size){
            item = new HashMap<String, String>();
            item.put("uid",uid);
            item.put("Sum","1");
            newsRegister.add(item);
        }
    }

    //获取某uid的计数值的方法
    public synchronized static String getSumByUid(String uid){
        HashMap<String,String> item;
        int size = newsRegister.size();
        int i;
        for(i = 0;i < size;i++){
            item = newsRegister.get(i);
            if(item.get("uid").equals(uid)) {
                return item.get("Sum");
            }
        }
        return "";
    }

    //获取消息总数的方法
    public synchronized static String getSum(){
        String Sum = "0";
        String sum = "0";
        HashMap<String,String> item;
        int size = newsRegister.size();
        for(int i = 0;i < size;i++){
            item = newsRegister.get(i);
            sum = item.get("Sum");
            Sum = String.valueOf((Integer.parseInt(sum)) + Integer.parseInt(Sum));
        }
        return Sum;
    }

    //清除所有计数值
    public static void clearAllRegister() {
        newsRegister = new ArrayList<HashMap<String, String>>();
    }
}
